package com.bk.bookviews.service.impl;

import com.bk.bookviews.domain.ResultMsg;
import com.bk.bookviews.domain.Title;
import com.bk.bookviews.domain.TitleExample;
import com.bk.bookviews.domain.TitleScenicExample;
import com.bk.bookviews.exception.BusinessException;
import com.bk.bookviews.exception.BusinessExceptionEnum;
import com.bk.bookviews.mapper.TitleMapper;
import com.bk.bookviews.mapper.TitleScenicMapper;
import com.bk.bookviews.service.TitleService;
import com.bk.bookviews.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
public class TitleServiceImpl implements TitleService {
    @Autowired
    private TitleMapper titleMapper;

    @Autowired
    private TitleScenicMapper titleScenicMapper;


    @Override
    public List<Title> selectTitleList() {
        TitleExample example = new TitleExample();
        example.createCriteria();
        return titleMapper.selectByExample(example);
    }

    @Override
    public void saveTitle(Title title) {
        titleMapper.insertSelective(title);
    }

    @Override
    public void delete(String titleId) {
        titleMapper.deleteByPrimaryKey(Long.parseLong(titleId));
        TitleScenicExample example = new TitleScenicExample();
        example.createCriteria().andTitleIdEqualTo(Long.parseLong(titleId));
        titleScenicMapper.deleteByExample(example);
    }
}
